package com.briup.oagg.facade.web.controller.model;

import com.briup.framework.utils.web.Response;
import com.briup.oagg.facade.service.model.IModelTrainConfigService;
import com.briup.oagg.facade.web.vm.model.ModelTrainConfigAddVM;
import com.briup.oagg.facade.web.vm.model.ModelTrainConfigPublishVM;
import com.briup.oagg.facade.web.vm.model.ModelTrainConfigVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模型训练配置信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "2.5.模型训练配置信息管理服务")
@RestController
@RequestMapping("/train")
public class ModelTrainConfigController {
    @Autowired
    private IModelTrainConfigService service;

    @ApiOperation(value = "多条件查询训练配置信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "modelType",value = "模型类型",allowableValues = "classification,cluster,regression",dataTypeClass = String.class),
            @ApiImplicitParam(name = "modelId",value = "模型编号",allowableValues = "classification,cluster,regression",dataTypeClass = String.class)
    })
    @GetMapping
    public Response<List<ModelTrainConfigVM>> findByCondition(String modelType,String modelId){
        List<ModelTrainConfigVM> list = service.findByCondition(modelType,modelId);
        return Response.success(list);
    }

    @ApiOperation(value = "根据训练编号查询指定模型训练配置信息")
    @GetMapping("/{trainId}")
    public Response<ModelTrainConfigVM> findByTrainId(@PathVariable String trainId){
        ModelTrainConfigVM vm = service.findByTrainId(trainId);
        return Response.success(vm);
    }

    @ApiOperation(value = "新建模型训练")
    @PostMapping
    public Response<String> addModelTrain(@RequestBody ModelTrainConfigAddVM vm){
        service.addModelTrain(vm);
        return Response.success();
    }

    @ApiOperation(value = "开启模型训练")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "trainId",value = "训练编号",paramType = "path"),
            @ApiImplicitParam(name = "modelId",value = "训练模型编号",paramType = "path")
    })
    @PostMapping(value = "/{trainId}/{modelId}")
    public Response<String> beginTrain(@PathVariable String trainId,
                                          @PathVariable String modelId){
        service.beginTrain(trainId,modelId);
        return Response.success();
    }


    @ApiOperation(value = "发布/取消模型训练")
    @ApiImplicitParam(name = "vm",value = "模型发布参数")
    @PutMapping
    public Response<String> publishTrain(@RequestBody ModelTrainConfigPublishVM vm){
        service.updatePublishTrain(vm);
        return Response.success();
    }

    @ApiOperation(value = "根据训练编号删除指定模型训练配置信息")
    @ApiImplicitParam(name = "trainId",value = "训练编号",paramType = "path",dataTypeClass = String.class)
    @DeleteMapping("/{trainId}")
    public Response<String> deleteByTrainId(@PathVariable String trainId){
        service.deleteByTrainId(trainId);
        return Response.success();
    }


}
